package company.shopee_F;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Shopee02 {

    //经过n次合并 找到最小的min个数 输出最大的数
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int min = sc.nextInt();
        List<Integer> list = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        int minSum, minIndex = 0;
        while (list.size() != min) {
            minSum = list.get(0) + list.get(1);
            for (int i = 1; i < list.size() - 1; i++) {
                int tmpSum = list.get(i) + list.get(i + 1);
                minIndex = 0;
                if (tmpSum < minSum) {
                    minIndex = i;
                    minSum = tmpSum;
                }
            }
            list.set(minIndex, minSum);
            list.remove(minIndex + 1);
        }
    }

    //------------------------------------------------------------------

}
